package com.sprouting.personal.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sprouting.personal.dao.MemberFamilyDao;
import com.sprouting.personal.dao.UserDao;
import com.sprouting.personal.dao.UserRoleDao;
import com.sprouting.personal.model.entity.MemberFamily;
import com.sprouting.personal.model.entity.User;
import com.sprouting.personal.model.entity.UserRole;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 登录用户表
 *
 * @author ：LX（长沙麓谷）
 * @date 创建时间： 2022/7/26 9:21
 */
@Service
@Slf4j
public class UserService extends ServiceImpl<UserDao, User> {

    @Resource
    private UserDao userDao;
    @Resource
    private MemberFamilyDao memberFamilyDao;
    @Resource
    private UserRoleDao userRoleDao;


    /**
     * 根据登录用户名查询登录用户名
     * @param loginUser 登录用户名
     * @return
     */
    public User getUserServiceByLoginUser(String loginUser) {
        return userDao.getUserServiceByLoginUser(loginUser);
    }

    /**
     * 保存用户信息-登录注册用户
     * @param user 登录信息
     * @param memberFamily 家庭成员信息
     * @param userRole 用户角色
     */
    @Transactional(rollbackFor = Exception.class)
    public void saveUser(User user, MemberFamily memberFamily, UserRole userRole) {
        userDao.insert(user);
        memberFamilyDao.insert(memberFamily);
        userRoleDao.insert(userRole);
    }
}
